package com.netease.financial.common.util;

import java.io.File;

import android.os.Environment;

/**
 * @author yufeng.wu
 *
 */
public class SDCardUtils {

    public static boolean isSDCardAvailable() {
        String sdStatus = Environment.getExternalStorageState();
        return Environment.MEDIA_MOUNTED.equals(sdStatus);
    }

    public static String getDownloadFileDirPath() {
        File file = new File(SDCardUtils.getAppFileDirPath(), "downloads");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file.getAbsolutePath();
    }

    public static String getConfigFileDirPath() {
        File file = new File(SDCardUtils.getAppFileDirPath(), "config");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file.getAbsolutePath();
    }

    public static String getAppFileDirPath() {
        File file = new File(SDCardUtils.getMainDirPath(), "financial");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file.getAbsolutePath();
    }

    public static String getMainDirPath() {
        File file = new File(SDCardUtils.getSDCardDir(), "netease");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file.getAbsolutePath();
    }

    public static String getSDCardDir() {
        try {
            return Environment.getExternalStorageDirectory().toString();
        } catch (Exception e) {
            return "";
        }
    }

}
